package io.renren.modules.job.task;


import io.renren.common.redis.RedisKeys;
import io.renren.common.redis.RedisUtils;
import io.renren.modules.oss.service.SysOssService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Set;


/**
 *定时清理垃圾图片
 */
@Slf4j
@Component("oosImageClean")
public class oosImageClean implements ITask{

    @Autowired
    private RedisUtils redisUtils;

    @Autowired
    private SysOssService sysOssService;

    @Override
    public void run(String params) {
        Set<String> set =  redisUtils.difference(RedisKeys.getFoodPicResources(), RedisKeys.getFoodPicDbResources());

        if (set!=null){
            for (String picName : set){
                sysOssService.deleteByKey(picName);
                redisUtils.remove(RedisKeys.getFoodPicResources(),picName);
                log.info("定时任务执行成功！清理垃圾图片:{}",picName);
            }
        }

    }

}
